//
//  SimpleAlertView.swift
//  E-CycleForShop
//
//  Created by enghou on 17/4/18.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

import UIKit

class SimpleAlertView: UIView {

    var dismissBlck : ()->Void = {
        
    }
    //180 60
    weak var supVi : UIView?
    class func show(dismissBlock : @escaping ()->Void,superView : UIView)->Void{
        let frm = CGRect.init(x: YXDeviceWidth / 2 - 150 * YXWidthScale, y: YXDeviceHeight - 200, width: 300 * YXWidthScale, height: 120 * YXHeightScale)
        let view = SimpleAlertView.init(frame: frm, dismissBlock: dismissBlock,superView: superView)
        view.show()
    }
    
    init(frame: CGRect,dismissBlock : @escaping ()->Void,superView : UIView) {
        super.init(frame: frame)
        let label = UILabel.init(frame: self.bounds)
        label.textColor = UIColor.white
        label.backgroundColor = UIColor.black
        label.text = "结算成功"
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 36 * YXWidthScale)
        self.addSubview(label)
        label.layer.masksToBounds = true
        label.layer.cornerRadius = 10//YXButtonCorner
        supVi = superView
        dismissBlck = dismissBlock
    }
    
    func show() -> Void {
        supVi?.addSubview(self)
        UIView.animate(withDuration: TimeInterval.init(2.0), animations: {()
            self.alpha = 0.0
        }, completion: {(finished) in
            self.dismissBlck()
            self.removeFromSuperview()
        })
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
